using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDF.Data;
using DDF.Data.Providers;
using System.Data;
using System.Linq.Expressions;
using System.Configuration;
using ARR.Entities.Gateways;

namespace ARR.DataModel.Repositories
{
	public static partial class CategoryUniverseRepository
	{
		private static string connString = ConfigurationManager.ConnectionStrings["Default"].ConnectionString;
		
		public class CategoryUniverseDbo : DatabaseObject
        {
            public CategoryUniverseDbo()
            {
                Name = "CategoryUniverse";
                GeneratedClassName = "CategoryUniverse";
                SequenceName = "N/A";
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Id", ColumnType = "smallint", IsIdentity = true, IsNullable = false, Length = 2, Precision = 5, Scale = 0, GeneratedPropertyName = "Id" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Universe", ColumnType = "varchar", IsIdentity = false, IsNullable = false, Length = 50, Precision = 0, Scale = 0, GeneratedPropertyName = "Universe" });
              
            }
        }
		
		public static List<CategoryUniverseRow> Select(Expression<Func<CategoryUniverseRow, bool>> expression)
        {
            List<CategoryUniverseRow> rows = new List<CategoryUniverseRow>();

            using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
            {
                IDataReader reader = database.Select<CategoryUniverseRow>(new CategoryUniverseDbo(), expression);

                Load(reader, rows);
            }

            return rows;
        }
		
		public static List<CategoryUniverseRow> Select()
		{
			List<CategoryUniverseRow> rows = new List<CategoryUniverseRow>();

			using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
			{
				IDataReader reader = database.Select<CategoryUniverseRow>(new CategoryUniverseDbo(), null);

				Load(reader, rows);
			}

			return rows;
		}
		
		public static List<CategoryUniverseRow> PagedSelect(Expression<Func<CategoryUniverseRow, bool>> filterExpression, Expression<Func<CategoryUniverseRow, object>> orderByExpression, int pageNumber, int pageSize)
		{
			List<CategoryUniverseRow> rows = new List<CategoryUniverseRow>();
			
			using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
			{
				IDataReader reader = database.PagedSelect<CategoryUniverseRow>(new CategoryUniverseDbo(), filterExpression, orderByExpression, pageNumber, pageSize);

				Load(reader, rows);
			}

			return rows;
		}
		
		private static void Load(IDataReader reader, List<CategoryUniverseRow> CategoryUniverseList)
        {
            CategoryUniverseRow row;

            while (reader.Read())
            {
                row = new CategoryUniverseRow()
                {
					Id = Util.CastDbValue<int>(reader["Id"]),
					Universe = Util.CastDbValue<string>(reader["Universe"])
                };
                                
                CategoryUniverseList.Add(row);
            }

            reader.Close();
        }

			
		public static void Insert(CategoryUniverseRow row)
        {
            using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
            {
                database.Insert<CategoryUniverseRow>(new CategoryUniverseDbo(), row);
            }
        }

		public static void Update(CategoryUniverseRow row)
        {
            using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
            {
                database.Update<CategoryUniverseRow>(new CategoryUniverseDbo(), row);
            }
        }

		public static void Delete(Expression<Func<CategoryUniverseRow, bool>> expression)
        {
            using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
            {
                database.Delete<CategoryUniverseRow>(new CategoryUniverseDbo(), expression);
            }
        }

	}
}
	
